﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Core;
using QxFramework.Utilities;

public class TurnController:MonoSingleton<TurnController>
{
    public int LastPlayer=1;
    public Player player1;
    public Player player2;
    public void Init()
    {
        Debug.Log("初始化玩家");
        player1 = new Player();
        player1.Id = 1;
        player2 = new Player();
        player2.Id = 2;
    }
    public void StartTurn(int id)
    {
        AudioManager.Instance.PlayEffectAudio("StartTurn", 0.5f);
        Debug.Log("进入玩家" + id + "的回合");
        if (id == 1)
        {
            LastPlayer = 1;
            player1.StartTurn();
            player2.StopMoving();
        }
        else
        {
            LastPlayer = 2;
            player2.StartTurn();
            player1.StopMoving();
        }
    }
    public void EndTurn()
    {
        if (LastPlayer == 1)
        {
            player1.StopMoving();
            StartTurn(2);

        }
        else
        {
            player2.StopMoving();
            StartTurn(1);
        }
    }
    public int GetLastPlayer()
    {
        return LastPlayer;
    }

    public void ChessInit()
    {
        foreach (var chess in player1.myChess)
        {
            Debug.Log("1");
            chess.player = player1;
            Map.Instance.cellDIC[chess.Pos].cellState = CellState.Chess;
        }
        foreach (var chess in player2.myChess)
        {
            Debug.Log("2");
            chess.player = player2;
            Map.Instance.cellDIC[chess.Pos].cellState = CellState.Chess;
        }
    }
    public Player GetPlayer(int Id)
    {
        if (Id == 1) return player1;
        else return player2;
    }
    public Player GetPlayer()
    {
        if (LastPlayer == 1) return player1;
        else return player2;
    }
}
